﻿#include<iostream>
#include<unordered_set>
#include<unordered_map>
#include<map>
#include<set>
#include<string>
using namespace std;
#include <time.h>

//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
//将哈希表改造，模拟实现map和set的代码
#include "UnorderedSet.h"
#include "UnorderedMap.h"
int main()
{
	unordered_set<int> us;
	us.insert(3);
	us.insert(1);
	us.insert(3);
	us.insert(2);
	us.insert(0);

	unordered_set<int>::iterator it = us.begin();
	while (it != us.end())
	{
		cout << *it << " ";
		++it;
	}
	cout << endl;

	string arr[] = { "苹果", "西瓜", "香蕉", "草莓", "苹果", "西瓜", "苹果", "苹果", "西瓜", "苹果", "香蕉", "苹果", "香蕉" };
		
	unordered_map<string, int> countMap;
	for (auto& e : arr)
	{
		//map<string, int>::iterator it = countMap
	/*	auto it = countMap.find(e);
		if (it == countMap.end())
		{
			countMap.insert(make_pair(e, 1));
		}
		else
		{
			it->second++;
		}*/

		countMap[e]++;
	}
		
	for (const auto& kv : countMap)
	{
		cout << kv.first << ":" << kv.second << endl;
	}

	return 0;
}


//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

//对比map和unordered_set的各项性能的代码
//int main()
//{
//	const size_t N = 100000;
//
//	unordered_set<int> us;
//	set<int> s;
//
//	vector<int> v;
//	v.reserve(N);
//	srand(time(0));
//	for (size_t i = 0; i < N; ++i)
//	{
//		//v.push_back(rand());
//		//v.push_back(rand()+i);
//		v.push_back(i);
//	}
//
//	size_t begin1 = clock();
//	for (auto e : v)
//	{
//		s.insert(e);
//	}
//	size_t end1 = clock();
//	cout << "set insert:" << end1 - begin1 << endl;
//
//	size_t begin2 = clock();
//	for (auto e : v)
//	{
//		us.insert(e);
//	}
//	size_t end2 = clock();
//	cout << "unordered_set insert:" << end2 - begin2 << endl;
//
//
//	size_t begin3 = clock();
//	for (auto e : v)
//	{
//		s.find(e);
//	}
//	size_t end3 = clock();
//	cout << "set find:" << end3 - begin3 << endl;
//
//	size_t begin4 = clock();
//	for (auto e : v)
//	{
//		us.find(e);
//	}
//	size_t end4 = clock();
//	cout << "unordered_set find:" << end4 - begin4 << endl;
//
//	cout << s.size() << endl;
//	cout << us.size() << endl;
//
//	size_t begin5 = clock();
//	for (auto e : v)
//	{
//		s.erase(e);
//	}
//	size_t end5 = clock();
//	cout << "set erase:" << end5 - begin5 << endl;
//
//	size_t begin6 = clock();
//	for (auto e : v)
//	{
//		us.erase(e);
//	}
//	size_t end6 = clock();
//	cout << "unordered_set erase:" << end6 - begin6 << endl;
//	
//	return 0;
//}

//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
//没有改造之前的哈希表代码
//#include "HashTable.h"
//
//int main()
//{
//	closehash::TestHT1();
//	closehash::TestHT2();
//
//	buckethash::TestHT1();
//	buckethash::TestHT2();
//
//
//	return 0;
//}